package work.tools.deadline
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class SimpleDeadline
	{
		public function SimpleDeadline(app:DisplayObject,endDate:Date,passDay:uint=0,pass:uint=0,startDate:Date=null)
		{
			if(app && app.stage)
			{
				if(startDate==null)
				{
					startDate=new Date();
				}
				var deadline:Deadline=new Deadline(startDate);
				deadline.addQualification(new QualificationEndDate(endDate));
				if(passDay>0)
				{
					deadline.addQualification(new QualificationPassDay(passDay));
				}
				if(pass>0)
				{
					deadline.addQualification(new QualificationOpenTotal(pass));
				}
				if(deadline.isPass())
				{
					var bg:Sprite=new Sprite();
					var s:Stage=app.stage;
					bg.graphics.beginFill(0xFFFFFF,1);
					bg.graphics.drawRect(0,0,s.stageWidth,s.stageHeight);
					bg.graphics.endFill();
					
					var txt:TextField=new TextField();
					txt.textColor=0x000000;
					txt.text="试用已经结束";
					var tf:TextFormat=new TextFormat(null,30);
					txt.setTextFormat(tf);
					
					txt.width=txt.textWidth+4;
					txt.height=txt.textHeight+2;
					txt.x=(s.stageWidth-txt.width)*0.5;
					txt.y=(s.stageHeight-txt.height)*0.5;
					
					s.addChild(txt);					
				}
			}else
			{
				throw new Error("app or app parent is null")
			}
		}
	}
}